﻿Partial Public Class PublisherCardData
	Public ReadOnly Property EnteredUtc() As Global.System.DateTime
		Get
			Return Entered '.ToUniversalTime
		End Get
	End Property

	Public Shared ReadOnly Property CurrentReportingMonth As DateTime
		Get
			Dim db As New CongregationDataContainerLocal

			Return Aggregate report In db.PublisherCardDatas
			   Select report.Month
			   Into Max()

		End Get
	End Property

	Public Shared Function RecentReports() As List(Of PublisherCardData)
		Dim db As New CongregationDataContainerLocal

		Dim myPublishersReports = From pubs In PublisherData.RecentPublishers()
		  Group Join report In db.PublisherCardDatas
		  On pubs.PublisherID Equals report.PublisherID
		  Into myRecentReports = Group
		 Select myRecentReports = myRecentReports.Where(Function(x) Not x.Reported AndAlso Not x.IsHistorical).ToList

		Dim returnReports As New List(Of PublisherCardData)

		For Each pub In myPublishersReports.ToList
			returnReports.AddRange(pub)
		Next

		Return returnReports

	End Function

	Public Shared Function ReportingPublishersReports() As List(Of PublisherCardData)
		Dim db As New CongregationDataContainerLocal

		Dim myPublishers = From pubs In PublisherData.RecentPublishers()
		 Group Join reports In db.PublisherCardDatas
		 On pubs.PublisherID Equals reports.PublisherID
		 Into PubReports = Group
		 Select RecentReports = PubReports.Where(Function(x) Not x.IsHistorical AndAlso Not x.IsAuxPioneer AndAlso Not x.IsPioneer AndAlso Not x.IsSpecialPioneer AndAlso Not x.Reported).ToList

		Dim returnReports As New List(Of PublisherCardData)

		For Each pub In myPublishers.ToList
			returnReports.AddRange(pub)
		Next

		Return returnReports

	End Function

	Public Shared Function ReportingAuxPioneersReports() As List(Of PublisherCardData)
		Dim db As New CongregationDataContainerLocal

		Dim myPublishers = From pubs In PublisherData.RecentPublishers()
		 Group Join reports In db.PublisherCardDatas
		 On pubs.PublisherID Equals reports.PublisherID
		 Into PubReports = Group
		 Select RecentReports = PubReports.Where(Function(x) Not x.IsHistorical AndAlso x.IsAuxPioneer AndAlso Not x.IsPioneer AndAlso Not x.IsSpecialPioneer AndAlso Not x.Reported).ToList

		Dim returnReports As New List(Of PublisherCardData)

		For Each pub In myPublishers.ToList
			returnReports.AddRange(pub)
		Next

		Return returnReports

	End Function

	Public Shared Function ReportingPioneersReports() As List(Of PublisherCardData)
		Dim db As New CongregationDataContainerLocal

		Dim myPublishers = From pubs In PublisherData.RecentPublishers()
		 Group Join reports In db.PublisherCardDatas
		 On pubs.PublisherID Equals reports.PublisherID
		 Into PubReports = Group
		 Select RecentReports = PubReports.Where(Function(x) Not x.IsHistorical AndAlso Not x.IsAuxPioneer AndAlso x.IsPioneer AndAlso Not x.IsSpecialPioneer AndAlso Not x.Reported).ToList

		Dim returnReports As New List(Of PublisherCardData)

		For Each pub In myPublishers.ToList
			returnReports.AddRange(pub)
		Next

		Return returnReports

	End Function


End Class

